package com.workflow.listener;

import com.gec.service.abst.ReimService;
import com.gec.utils.MyWebUtils;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

public class ReimEndHandler implements ExecutionListener {
	private final ReimService reimService;

	public ReimEndHandler()
	{
		this.reimService = MyWebUtils.getBean(ReimService.class);;
	}

	@Override
	public void notify(DelegateExecution delegateExecution)
	{
		//[1] 获取流程变量 cancel
		boolean isCancel = Boolean.parseBoolean((String) delegateExecution.getVariable("isCancel"));
		//[2] 根据流程变量设置 '已取消' '已办结'
		String status = isCancel ? "已取消" : "已办结";
		//[3] 获取流程实例Id
		String processInstanceId = delegateExecution.getProcessInstanceId();
		//[4] 更新 t_leave表 中的状态
		reimService.updateStatusByInstance(processInstanceId, status);
		//[5] 清空办理人与任务
		reimService.clearTaskAndAssignee(processInstanceId);
	}
}
